package com.jlkf.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jlkf.dao.EditionMapper;
import com.jlkf.pojo.CarCaculation;
import com.jlkf.pojo.Edition;
import com.jlkf.service.EditionService;
import com.platform.server.response.pojo.ReturnData;
import com.platform.server.util.RegexUtil;
import com.platform.server.util.StringTools;

@Service
public class EditionServiceImpl implements EditionService{

	@Autowired
	private EditionMapper editionMapper;
	
	@Override
	public ReturnData addOrUpdate(String json) {
		Edition e = StringTools.json2Obj(json, Edition.class);
		e.setCreateTime(new Date());
		try {
			int num=editionMapper.insertSelective(e);
			if(num==0){
				return new ReturnData(201,"fail");
			}
			return new ReturnData(200,"success");
		} catch (Exception ex) {
			ex.printStackTrace();
			return new ReturnData(500,"Wow, that's wrong");
		}
	}

	
	@Override
	public ReturnData getList(Integer pageNo, Integer pageSize) {
		if(RegexUtil.isNull(pageNo)){
			pageNo=1;
		}
		if(RegexUtil.isNull(pageSize)){
			pageSize=10;
		}
		try {
			PageHelper.startPage(pageNo, pageSize);
			List<Edition> list=editionMapper.getList();
			PageInfo<Edition> info = new PageInfo<>(list);
			return new ReturnData(list,info.getPages(),(int)info.getTotal(),"success");
		} catch (Exception ex) {
			ex.printStackTrace();
			return new ReturnData(500,"Wow, that's wrong");
		}
	}

	
	
}
